package com.tbit.uqbike.webmanager.util.csv.config;

import lombok.Getter;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * @AUTHOR: wei.xing
 * @DATE: 2022-11-19 15:36
 **/
@Component
@Getter
public class ExportThreadPool {

    ExecutorService executor;

    public ExportThreadPool(CsvExportConfig config) {
        executor = new ThreadPoolExecutor(
                config.getCorePoolSize(),
                config.getMaxPoolSize(),
                config.getKeepAliveTime(), TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(config.getQueueCapacity()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }

    public void execute(Runnable runnable) {
        executor.execute(runnable);
    }

}
